﻿using ArrayConsoleRender;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace CheckSort
{
    public enum SortMode:uint
    {
        ShellSort=0,
        BubleSort=1
    };

    public enum ArrayType : uint
    {
        SortedArray=0,
        DescSortedArray=1,
        RamdomArray=2
    };


    public struct ArrayParams
    {
        public SortMode modeOfSort;
        public uint lenght;
        public ArrayType typeOfArray;
    }

    class Program
    {
        static void Main()
        {

            CallSortTest();
        }

        public static void CallSortTest()
        {
            ArrayParams arrP;
            DateTime timeStart = DateTime.MinValue;
            DateTime timeEnd = DateTime.MinValue;
            arrP = PrintMenu();
            int[] arr = new int[arrP.lenght];

            switch (arrP.typeOfArray)
            {
                case ArrayType.SortedArray:
                    CreateArray.CreateSortedArray(arrP.lenght, arr);
                    break;
                case ArrayType.DescSortedArray:
                    CreateArray.CreateDescSortedArray(arrP.lenght, arr);
                    break;
                case ArrayType.RamdomArray:
                    CreateArray.CreateRamdomArray(arrP.lenght, arr);
                    break;
            }
            switch (arrP.modeOfSort)
            {
                case SortMode.ShellSort:
                    timeStart = DateTime.Now;
                    ArraySort.ShellSort(arr);
                    timeEnd = DateTime.Now;
                    break;
                case SortMode.BubleSort:
                    timeStart = DateTime.Now;
                    ArraySort.BubleSort(arr);
                    timeEnd = DateTime.Now;
                    break;
                default:
                    timeStart = DateTime.Now;
                    ArraySort.BubleSort(arr);
                    timeEnd = DateTime.Now;
                    break;
            }
            PrintDuration(timeStart, timeEnd);
            Console.WriteLine(Literals.DRAW);
            uint draw = Utils.EnterUint(1);
            if (draw == 1)
            {
                CreateArray.CreateRamdomArray(arrP.lenght, arr);
                Console.SetWindowPosition(0, 0);
                switch (arrP.modeOfSort)
                {
                    case SortMode.ShellSort:
                        ArraySort.ShellSortIllustraited(arr);
                        break;
                    default:
                        ArraySort.BubleSortIllustraited(arr);
                        break;
                }
            }
            Console.WriteLine();
            Console.WriteLine(Literals.AGAIN);
            uint again = Utils.EnterUint(1);
            if (again == 1)
            {
                Console.WriteLine();
                CallSortTest();
            }
        }

        private static void PrintDuration(DateTime timeStart, DateTime timeEnd)
        {
            TimeSpan duration = TimeSpan.Zero;
            duration = timeEnd - timeStart;
            Console.Write(Literals.DURATION);
            Console.WriteLine(duration.TotalMilliseconds);
        }
        public static ArrayParams PrintMenu()
        {
            ArrayParams arrParam;
            Console.WriteLine(Literals.ENTERMODE);
            arrParam.modeOfSort = (SortMode)Utils.EnterUint(2);
            Console.WriteLine(Literals.LENGHT);
            arrParam.lenght = Utils.EnterUint(2000000);
            Console.WriteLine(Literals.TYPE);
            arrParam.typeOfArray = (ArrayType)Utils.EnterUint(2);
            return arrParam;
        }

    }
}
